# -*- coding:utf-8 -*-
# 版权所有 (c) 华为技术有限公司 2023. All rights reserved.
# Copyright (c) Huawei Technologies Co., Ltd. 2023. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import sys

import numpy as np

LOSS = 1e-4
MINIMUM = 10e-10


def verify_result(real_result, golden, data_type=np.uint32):
    real_result = np.fromfile(real_result, dtype=data_type)
    print(real_result)
    golden = np.fromfile(golden, dtype=data_type)
    print(golden)
    result = np.abs(real_result - golden)
    deno = np.maximum(np.abs(real_result), np.abs(golden))
    result_atol = np.less_equal(result, LOSS)
    result_rtol = np.less_equal(result / np.add(deno, MINIMUM), LOSS)
    if not result_rtol.all() and not result_atol.all():
        if np.sum(not result_rtol) > real_result.size * LOSS and np.sum(not result_atol) > real_result.size * LOSS:
            print("[ERROR] result error")
            return False
    print("test pass")
    return True


if __name__ == '__main__':
    verify_result(sys.argv[1], sys.argv[2])
